package com.heima.nio.socket.client;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;

/**
 * @author ZhengDp
 * @Date 2023/6/23 14:35
 */
@Slf4j
public class Client {
    public static void main(String[] args) throws IOException {
        // 1. 创建客户端
        SocketChannel client = SocketChannel.open();
        log.info("Client Connecting ... ");
        // 2. 建立连接
        client.connect(new InetSocketAddress("localhost", 7777));
        log.info("Client Connected ... ");
        // 3. 写入数据
        client.write(StandardCharsets.UTF_8.encode("hello client"));
        log.info("Client Writed : Hello Client ");

    }
}
